import { getBaseUrl } from '@/services/urlconst';
import { getUserID, requestFunComponFiex } from '@/utils';
import { useMemo } from 'react';
import { useRequest } from 'umi';

const baseUrl = getBaseUrl();
// const baseUrl = '/wenchuang';

/* ================================================== 领用AO Service START ================================================= */
/** 获取领用详情 */
export const detailAssetApplyUesServices = (Callback: (res: Record<string, any>) => void) => {
  const request = useRequest(
    (payload) => {
      let bodyParams = {
        ...payload,
      };
      let reqUrl = `${baseUrl}/assetApplyUes/detail/${bodyParams?.id}/${getUserID()}`;
      return requestFunComponFiex('GET', reqUrl, bodyParams);
    },
    {
      manual: true,
      onSuccess: Callback,
    },
  );
  return {
    detailAssetApplyUesRun: request?.run,
    detailAssetApplyUesLoading: request?.loading,
    detailAssetApplyUesReload: request?.refresh,
  };
};

/**
 * 查看当前流程进度
 * @controller 业务controller
 * @returns
 */
export const getImageByProcInstIDService = (callBack: (res: any) => void) => {
  const getImageByProcInstID = useRequest(
    (params: any) => {
      let personUrl = `${baseUrl}/assetApplyUes/getImageByProcInstID/${params?.procInstID}`;
      return requestFunComponFiex('GET', personUrl, {});
    },
    {
      manual: true,
      onSuccess: callBack,
    },
  );

  const data = useMemo(() => {
    return getImageByProcInstID?.data;
  }, [getImageByProcInstID?.data]);

  return {
    getImageByProcInstIDRun: getImageByProcInstID?.run,
    getImageByProcInstIDLoading: getImageByProcInstID?.loading,
    getImageByProcInstIDData: data,
  };
};

/**同步PDF - 领用*/
export const syncPDFtoOAServicesUse = (cb: (res: Record<string, any>) => void) => {
  const request = useRequest(
    (payload) => {
      let reqParams = { ...payload };
      let reqUrl = `${baseUrl}/assetApplyUes/syncWorkFlow`;
      return requestFunComponFiex('POST', reqUrl, reqParams);
    },
    {
      manual: true,
      onSuccess: cb,
    },
  );

  return {
    syncPDFtoOARun: request?.run,
    syncPDFtoOALoading: request?.loading,
  };
};

/* ================================================== 领用AO Service START ================================================= */
